

#include "stdafx.h"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	char *str="mfile.bin";
	system("del mfile.bin");
	FILE *stream;
	__int64 Data[10]={1,268144,055,2,0,2,1,222888,100000,-1};
	__int64 OutData[10];
	stream=fopen("1.dtb","a+b");
	fwrite(Data,sizeof(Data[0]),10,stream);
	fseek(stream,0,SEEK_SET);
	fread(OutData,sizeof(Data[0]),10,stream);
	for (int i=0; i<10; i++)
		cout<<Data[i]<<" ";
	cout<<endl;
	for (int i=0; i<10; i++)
		cout<<OutData[i]<<" ";
	cout<<endl<<" ";
	getch();
	fcloseall();
	TFile f;
	f.Open("tfile.bin",P_ADD|P_UPDATE|P_BINARY);
	f.Write(Data,sizeof(__int64),10);
	f.Seek(0,S_BEGIN);
	f.Read(OutData,8,10);
	for (int i=0; i<10; i++)
		cout<<OutData[i]<<" ";
	cout<<endl<<" ";
	getch();
	fcloseall();
	DTBFile fd;
	fd.Open("dtbfile.bin");
	time_t tt=0;
	time(&tt);
	fd.Write(tt,150);
	time_t ct;
	time(&ct);
	time(&tt);
	fd.Write(tt,600);
	fd.GoToBlock(0);
	cout<<endl<<fd.GetTime();
	cout<<endl<<fd.GetPing();
	fd.GoToNextBlock();
	cout<<endl<<fd.GetTime();
	cout<<endl<<fd.GetPing();
	getch();
	fd.SeekToTime(ct);
	cout<<endl<<fd.GetTime();
	cout<<endl<<fd.GetPing();
	getch();
	MFile mf;
	mf.Open("mfile.bin");
	mf.Write(32759,"127.0.0.1");
	mf.Write(38564,"127.0.0.2");
	mf.Write(39458,"127.0.0.3");
	mf.Write(32952,"150.24.7.99");
	mf.Write(32953,"ya.ru");
	fseek(mf.GetFile(),0,0);
	system("cls");
	char buf[256];
	memset(buf,0,256);
	mf.GetURL(buf);
	cout<<mf.GetID()<<" "<<buf;
	getch();
	DataBase db;
	db.Create(1,"database.bin",3,5000);
	db.AddInfo(1,10,150);
	db.AddInfo(1,20,150);
	db.AddInfo(1,30,150);
	getch();
	DTBFile dbf;
	dbf.Open("database.bin");
	cout<<dbf.GetTime()<<endl<<dbf.GetPing()<<endl;
	dbf.GoToNextBlock();
	cout<<dbf.GetTime()<<endl<<dbf.GetPing()<<endl;
	fseek(dbf.GetFile(),0,S_END);
	cout<<ftell(dbf.GetFile());
	getch();
	DBManager mgr;
	mgr.LoadDatabaseListFromFile("mfile.bin");
	system("cls");
	cout<<mgr.uiCount;
	getch();
	PingData pd;
	time(&tt);
	pd.Init(5,tt);
	uint ids[5];
	for (int i=0; i<5; i++)
	{
		ids[i]=mgr.GetDBId(i);
		pd.SetIdp(i,ids[i]);
		pd.SetPing(i,100*i+100);
	}
	char *d=new char [256];
	uint tmp=CreatePingDataMessage(d,pd);
	mgr.TranslateMessage(d,tmp);
	mgr.TranslateMessage(d,tmp);
	mgr.TranslateMessage(d,tmp);
	mgr.TranslateMessage(d,tmp);
	mgr.TranslateMessage(d,tmp);
	//	Sleep(5000);
	//	mgr.Update(GetTickCount());
	//	getch();
	fcloseall();
	MFile nmf;
	nmf.Open("mfile.bin");
	memset(d,0,256);
	nmf.GoToNextBlock();
	nmf.GetURL(d);
	fcloseall();
	DTBFile df;
	df.Open(d);
	cout<<endl<<df.GetPing()<<endl<<d;
	getch();

	return 0;
}

